package com.atguigu.userservice.controller.front;


import com.atguigu.commonutils.R;
import com.atguigu.userservice.entity.HangYeItem;
import com.atguigu.userservice.entity.RepUser;
import com.atguigu.userservice.service.RepUserService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@Api(description = "首页接口类")
@RestController
@RequestMapping("/userservice/indexfront")
@CrossOrigin
public class IndexFrontController {

    @Autowired
    private RepUserService userService;

    //查询前4个热门领域和8个店铺
    @ApiOperation("查询前4个热门领域和8个店铺")
    @GetMapping("index")
    public R index() {
        //查询前8个店铺
        LambdaQueryWrapper<RepUser> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(RepUser::getType, "2");
        wrapper.orderByDesc(RepUser::getMobile);
        wrapper.last("limit 8");
        List<RepUser> shangJia = userService.list(wrapper);


        List<HangYeItem> hangYeItemList = new ArrayList<>();
        HangYeItem item1 = new HangYeItem();
        item1.setAvatar("https://edu-7734.oss-cn-guangzhou.aliyuncs.com/2021/10/21/d00b0f36e6854fae9e1b2b52b8ab813f手机行业1.jpg");
        item1.setName("苹果手机维修");


        HangYeItem item2 = new HangYeItem();
        item2.setAvatar("https://edu-7734.oss-cn-guangzhou.aliyuncs.com/2021/10/21/e3299a364495430eb16b8533fb80f80d手机店铺1.jpg");
        item2.setName("手机维修");


        HangYeItem item3 = new HangYeItem();
        item3.setAvatar("https://edu-7734.oss-cn-guangzhou.aliyuncs.com/2021/10/21/870322b1774142eb955eaba90e125b62空调维修.jpg");
        item3.setName("空调维修");


        HangYeItem item4 = new HangYeItem();
        item4.setAvatar("https://edu-7734.oss-cn-guangzhou.aliyuncs.com/2021/10/21/2c8903a5128d43f0a09891599c6c9048综合维修.jpg");
        item4.setName("综合维修");
        hangYeItemList.add(item1);
        hangYeItemList.add(item2);
        hangYeItemList.add(item3);
        hangYeItemList.add(item4);

        //查询前4个领域
//        QueryWrapper<EduTeacher> wrapperTeacher = new QueryWrapper<>();
//        wrapperTeacher.orderByDesc("id");
//        wrapperTeacher.last("limit 4");
//        List<EduTeacher> teacherList = teacherService.list(wrapperTeacher);

        //查询前4个领域
//        LambdaQueryWrapper<RepUser> wrapper1 = new LambdaQueryWrapper<>();
//        wrapper.eq(RepUser::getType, "1");
//        wrapper.orderByDesc(RepUser::getMobile);
//        wrapper.last("limit 8");
//        List<RepUser> shangJia = userService.list(wrapper);


        return R.ok().data("shangJia", shangJia).data("hangYe",hangYeItemList);

//        return R.ok().data("eduList", eduList).data("teacherList", teacherList);
    }
}
